define(function(require,exports,module){
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	
	module.exports = {
		initComponent: function(params,widget){
			var subnav = new Subnav({
				parentNode: ".J-subnav",
				model: {
					title: "入住前调整",
					items: [{
						id:"destination",
						type: "buttongroup",
						url: "api/nonmembergroup/querydestnandserpoint",
						tip: "目的地",
						lazy: true,
						keyField: "strKey",
						valueField: "name",
						handler: function(){
							widget.get("grid").refresh();
						}
					},{
			            id: "dateRange",
			            type: "daterange",
			            tip: "入住时间-退住时间",
			            ranges: {
			                "今天": [moment().startOf("days"), moment().endOf("days")],
			                "本月": [moment().startOf("month"), moment().endOf("month")]
			            },
			            defaultRange: "本月",
			            minDate: "1930-05-31",
			            maxDate: "2020-12-31",
			            handler: function(time) {
			            	widget.get("grid").refresh();
			            }
			        },{
			        	id:"cancel",
			        	text:"整团取消",
			        	type:"button",
			        	show : false,
			        	handler:function(){
			        		var adjsutForm = widget.get("adjsutForm"),
			        		dataSource = adjsutForm.getValue("dataSource");
			        		if(dataSource == "NonMember"){
			        			var data = {
			        					pkNonMemberGroup : adjsutForm.getValue("pkGroup"),
			        					version : adjsutForm.getValue("version"),
			        					adjustTypes : "Abolished",
			        					adjustDate : new Date().getTime(),
			        					isAdjustment : true,
			        					isAbolished:true,
			        					status:adjsutForm.getValue("status")
			        			};
			        			Dialog.confirm({
			        				title:"提示",
			        				content:"确定该团整团取消吗？",
			        				confirm:function(){
			        					widget.service.allNonMemCancelSvc(data,function(ret){
					        				widget.toGrid();
					        				widget.get("grid").refresh();
					        			})
			        				}
			        			});			        			
			        		}else{
			        			var data = {
			        					pkPlanItemGroup : adjsutForm.getValue("pkGroup"),
			        					version : adjsutForm.getValue("version"),
			        					adjustTypes : "Abolished",
			        					adjustDate : new Date().getTime(),
			        					isAdjustment : true,
			        					isAbolished:true
			        			};
			        			Dialog.confirm({
			        				title:"提示",
			        				content:"确定该团整团取消吗？",
			        				confirm:function(){
			        					widget.service.allMemCancelSvc(data,function(ret){
					        				widget.toGrid();
					        				widget.get("grid").refresh();
					        			})
			        				}
			        			});		
			        		}
			        	}
			        },{
			        	id:"save",
			        	text:"保存",
			        	type:"button",
			        	show : false,
			        	handler:function(){	
									var endDate = $(":input[name='checkOutDate']").val();
									var startDate = $(":input[name='checkInDate']").val();
									
									if(startDate != null && endDate < startDate){
										Dialog.alert({
		                      				 tip : "提示",
		                      				 content : "结束日期不能小于开始日期！"
		                      			 });
										return false;
									}
			        		if(widget.NonMember){
			        			widget.nonMemHandler.saveAdjust(widget);
			        		}else{
			        			widget.handler.saveEvent(widget);
			        		}
			        	}
			        },{
						id:"return",
						type:"button",
						text:"返回",
						show : false,
						handler:function(){
							widget.toGrid();
							widget.set("check",false);
						}
					}]
				}
			});
			
			widget.set("subnav",subnav);
		}
	};
});